package 作业;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentService {
    //规定当前集合 装学生
    Scanner scanner = new Scanner(System.in);
    ArrayList<Student> studentList = new ArrayList();

    public void printStudent(){

        for (int i = 0; i < studentList.size(); i++) {
            Student student = studentList.get(i);

        }
    }

    public void add() {
        System.out.println("请输入学生姓名:");
        String name = scanner.next();
        System.out.println("请输入学生的年龄:");
        int age = scanner.nextInt();
        Student student = new Student();
        student.setName(name);
        student.setAge(age);
        studentList.add(student);

    }

    public static class KTV {

        private ArrayList<String> songList = new ArrayList<>();

        public static void main(String[] args) {
            KTV system = new KTV();
            system.start();
        }

        public void start() {
            Scanner scanner = new Scanner(System.in);

            System.out.println("------欢迎来到点歌系统------");
            System.out.println("1.添加歌曲至列表");
            System.out.println("2.将歌曲置顶");
            System.out.println("3.将歌曲前移一位");
            System.out.println("4.退出");
            System.out.println("5.查看歌曲列表");
            System.out.println("6.删除歌曲信息");

            int choice;
            while (true) {
                System.out.print("请输入指令(1-6): ");
                choice = scanner.nextInt();
                scanner.nextLine();

                switch (choice) {
                    case 1:
                        this.addSong(scanner);
                        break;
                    case 2:
                        this.moveSongToTop(scanner);
                        break;
                    case 3:
                        this.moveSongUp(scanner);
                        break;
                    case 4:
                        System.out.println("退出系统。");
                        return;
                    case 5:
                        this.showSongs();
                        break;
                    case 6:
                        this.deleteSong(scanner);
                        break;
                    default:
                        System.out.println("无效的指令，请重新输入。");
                }
            }
        }

        private void addSong(Scanner scanner) {
            System.out.print("请输入歌曲名: ");
            String songName = scanner.nextLine();
            songList.add(songName);
            System.out.println("当前歌曲列表: " + songList);
        }

        private void moveSongToTop(Scanner scanner) {
            System.out.print("请输入要置顶的歌曲名: ");
            String songName = scanner.nextLine();
            int index = songList.indexOf(songName);
            if (index != -1) {
                songList.remove(index);
                songList.add(0, songName);
                System.out.println("歌曲已置顶，当前歌曲列表: " + songList);
            } else {
                System.out.println("歌曲不存在，无法置顶。");
            }
        }

        private void moveSongUp(Scanner scanner) {
            System.out.print("请输入要前移的歌曲名: ");
            String songName = scanner.nextLine();
            int index = songList.indexOf(songName);
            if (index != -1 && index > 0) {
                songList.remove(index);
                songList.add(index - 1, songName);
                System.out.println("歌曲已前移，当前歌曲列表: " + songList);
            } else {
                System.out.println("歌曲不存在或已在首位，无需前移。");
            }
        }

        private void showSongs() {
            System.out.println("当前歌曲列表: " + songList);
        }

        private void deleteSong(Scanner scanner) {
            System.out.print("请输入要删除的歌曲名: ");
            String songName = scanner.nextLine();
            int index = songList.indexOf(songName);
            if (index != -1) {
                songList.remove(index);
                System.out.println("歌曲已删除，当前歌曲列表: " + songList);
            } else {
                System.out.println("歌曲不存在，无法删除。");
            }
        }
    }

    public static class StudentManagerDemo {//学生管理 案例

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            //规定当前集合 装学生
            ArrayList<Student> studentList = new ArrayList();
            while (true){
                System.out.println("选择(1、录入;)");
                System.out.println("(0、退出;)");
                int choice = scanner.nextInt();
                if (choice == 1){
                    System.out.println("请输入学生姓名:");
                    String name = scanner.next();
                    System.out.println("请输入学生的年龄:");
                    int age = scanner.nextInt();

                    Student student = new Student();
                    student.setName(name);
                    student.setAge(age);
                    studentList.add(student);
                } else if (choice == 0) {

                    for (int i = 0; i < studentList.size(); i++) {
                        Student student = studentList.get(i);
                        // System.out.println(student.getName() + "---" + student.getAge());
                    }

                    //                for (Student s : studentList) {
                    //                    System.out.println(s);
                    //                }
                    break;

                }
            }






            //        System.out.println(studentList);


        }


    }
}
